﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Manage_basisset_Company : AdminPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckAdmin();
        GetUserPermisions();
        if (!IsPostBack)
        {
          
            GridViewBind();
        }
    }
    protected void CheckAdmin()
    {
        if (AdminSessionHelper.UserDetails == null)
        {
            JsHelper.TopAlertRedirect("请先登录", "../login.aspx", this.Page);
        }
    }
    protected void GridViewBind()
    {
        DataSet ds = jtDataAccess.GetCompany();
        if (CoreTools.CheckDataSet(ds))
        {

            // GridView绑定并显示数据
            this.GridView1.DataSource = ds.Tables[0];
            this.GridView1.DataBind();
        }

    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //首先判断是否是数据行
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标停留时更改背景色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FCFDEE'");
            //当鼠标移开时还原背景色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
        }
        if (edit == 1)
            ((CommandField)GridView1.Columns[6]).ShowEditButton = true;
        else
            ((CommandField)GridView1.Columns[6]).ShowEditButton = false;
        if (delete == 1)
            ((CommandField)GridView1.Columns[6]).ShowDeleteButton = false;
        else
            ((CommandField)GridView1.Columns[6]).ShowDeleteButton = false;
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        GridViewBind();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        GridViewBind();
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        int flag = 0;
        TextBox txtname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtName");
        TextBox txttel1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtTel1");
        TextBox txttel2 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtTel2");
        TextBox txtTax1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtTax1");
        TextBox txtTax2 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtTax2");
        TextBox txtUrl = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtUrl");
        string name = txtname.Text;
        name = name.Trim();
        if (name == "")
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("公司名称不能为空！"), false);
            txtname.Focus();
        }
        else
        {
            if (CoreTools.ProcessSqlStr(name, 0)&&CoreTools.ProcessSqlStr(txttel1.Text.Trim(), 0)&&CoreTools.ProcessSqlStr(txttel2.Text.Trim(), 0)&&CoreTools.ProcessSqlStr(txtTax1.Text.Trim(), 0)&&CoreTools.ProcessSqlStr(txtTax2.Text.Trim(), 0)&&CoreTools.ProcessSqlStr(txtUrl.Text.Trim(), 0))
            {

                flag = jtDataAccess.SetCompany(name,txttel1.Text.Trim(),txttel2.Text.Trim(),txtTax1.Text.Trim(),txtTax2.Text.Trim(),txtUrl.Text.Trim());

                switch (flag)
                {
                   
                    case 0:
                        ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作失败，请重试！"), false);
                        break;
                    default:
                        ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作成功！"), false);

                        break;
                }
                GridView1.EditIndex = -1;
                GridViewBind();
            }
            else
            {
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
               
            }
        }

    }
   
   
}